package com.css.msgcenter.admin.msgapp.action;

import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.dict.action.DirDict;
import com.css.msgcenter.server.QueryMsg;
import com.css.msgcenter.server.model.MsgApp;
import com.css.util.DesUtil;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

public class GetMsgApp extends AdminAction{
	private static Log log = LogFactory.getLog(DirDict.class);
	private String uuid;
	private MsgApp msgApp;
	private String mailSmtpHost;
	private String mailUser;
	private String mailPassword;
	private String ips;
	
	public GetMsgApp() {
		msgApp = new MsgApp();
	}
	@Override
	public String adminGo() {
		try {
			if(StringHelper.isNotEmpty(uuid)){
				msgApp = QueryMsg.get(MsgApp.class, uuid);
				if(msgApp == null){
					setMessage(Messages.getString("systemMsg.readError"));
					return Action.ERROR;
				}
				JSONObject  jasonObject = JSONObject.fromObject(msgApp.getMemo());
				Map map = (Map)jasonObject;
				mailSmtpHost = (String) map.get("mail.smtp.host");
				mailUser = (String) map.get("mail.user");
				mailPassword = (String) map.get("mail.password");
				mailPassword = DesUtil.decrypt(mailPassword);
				
			} 
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			setMessage(Messages.getString("systemMsg.dbFaild"));
			return Action.ERROR;
		} 
	}
	
	public String getUuid() {
		return uuid;
	}
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}
	public MsgApp getMsgApp() {
		return msgApp;
	}
	public void setMsgApp(MsgApp msgApp) {
		this.msgApp = msgApp;
	}
	public String getMailSmtpHost() {
		return mailSmtpHost;
	}
	public void setMailSmtpHost(String mailSmtpHost) {
		this.mailSmtpHost = mailSmtpHost;
	}
	public String getMailUser() {
		return mailUser;
	}
	public void setMailUser(String mailUser) {
		this.mailUser = mailUser;
	}
	public String getMailPassword() {
		return mailPassword;
	}
	public void setMailPassword(String mailPassword) {
		this.mailPassword = mailPassword;
	}
	public String getIps() {
		return ips;
	}
	public void setIps(String ips) {
		this.ips = ips;
	}

}